#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "../Regex.h"
#include "../Vector.h"

int main(void) {
  const char text0[100] = " ";
  const char text1[100] = "matches";
  const char text2[100] = "doesn't match";
  Regex*     regex      = regex_new("(es)$", 0);
  Regex*     regex2     = regex_new("[\\t\\n\\r ]+", 0);
  Vector*    result     = NULL;
  char*      str        = NULL;

  if (regex_matches(regex2, text0))
    printf("Correctly matches.\n");
  else
    printf("Incorrectly does not match.\n");

  if (regex_matches(regex, text1))
    printf("Correctly matches.\n");
  else
    printf("Incorrectly does not match.\n");

  if (regex_matches(regex, text2))
    printf("Incorrectly matches.\n");
  else
    printf("Correctly does not match.\n");

  result = regex_search(regex, text1);
  str    = vector_get(result, 0);
  if (result == NULL)
    printf("Incorrect result (NULL).\n");
  else if (strcmp(str, "es") != 0)
    printf("Incorrect match string '%s'\n", str);
  else
    printf("Correct match string '%s'\n", str);

  free(str);
  vector_free(result);

  regex_free(regex);
  return 0;
}
